home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / FlightSim / fxGrid.c < prev    next >
C/C++ Source or Header  |  1992-12-11  |  2KB  |  125 lines

  1. #include "flight.h"
  2.  
  3.  
  4. FxVector    fxGrid[GRID_SZ][GRID_SZ];
  5. FxVector    fxGridRot[GRID_SZ][GRID_SZ];
  6. FxVector    fxOriginV = {0, 0, 0};
  7.  
  8. FracThreeMatrx    fracRotatMatrx;
  9. FxThreeMatrx    transpCurrFxRotMatrx;
  10.  
  11. Fract    sinPtOne, cosPtOne, sinPtTwo, cosPtTwo;
  12. Fract    sinNPtOne, cosNPtOne, sinNPtTwo, cosNPtTwo;
  13.  
  14. extern    WindowPtr        theWind;    /*the main window*/
  15.  
  16.  
  17. MakeGrid()
  18. {
  19.     int    i, j;
  20.     Fixed    xVal, yVal, zVal;
  21.  
  22.     MkPort(theWind);
  23.     InitVars();
  24.  
  25.     yVal = iToFix(-100);
  26.     zVal = iToFix(-startHeight);
  27.  
  28.     for (i = 0; i < GRID_SZ; i++)
  29.     {
  30.         xVal = iToFix(-200);
  31.         for (j = 0; j < GRID_SZ; j++)
  32.         {
  33.             fxGrid[i][j].x = xVal;
  34.             fxGrid[i][j].y = yVal;
  35.             fxGrid[i][j].z = zVal;
  36.             xVal += iToFix(25);
  37.         }
  38.         yVal += iToFix(25);
  39.     }
  40.     BlockMove(fxGrid, fxGridRot, (long)64 * sizeof(FxVector));
  41.  
  42.     for (i = 0; i < GRID_SZ; i++)
  43.         FxPlotLine(&fxGrid[i][0], &fxGrid[i][GRID_SZ - 1]);
  44.  
  45.     for (j = 0; j < GRID_SZ; j++)
  46.         FxPlotLine(&fxGrid[0][j], &fxGrid[GRID_SZ - 1][j]);
  47. }
  48.  
  49. InitVars()
  50. {
  51.     int        i, j;
  52.  
  53.     for (i = 0; i < 3; i++)
  54.         for (j = 0; j < 3; j++)
  55.             if (i EQ j)
  56.                 fracRotatMatrx[i][j] = FRAC_ONE;
  57.             else
  58.                 fracRotatMatrx[i][j] = 0;
  59.     for (i = 0; i < 3; i++)
  60.         for (j = 0; j < 3; j++)
  61.             if (i EQ j)
  62.                 transpCurrFxRotMatrx[i][j] = FIX_ONE;
  63.             else
  64.                 transpCurrFxRotMatrx[i][j] = 0;
  65.  
  66. /*    sinPtOne = FracSin(DToFix(.1));*/
  67. {double    l;
  68. l = (long)
  69.         ldexp(0.1,16);
  70. }
  71.  
  72. sinPtOne = FracSin(
  73.         (long)
  74.         ldexp(0.1,16)
  75.         );
  76.  
  77.  
  78.     cosPtOne = FracCos(DToFix(.1));
  79.     sinPtTwo = FracSin(DToFix(.2));
  80.     cosPtTwo = FracCos(DToFix(.2));
  81.     sinNPtOne = FracSin(DToFix(-.1));
  82.     cosNPtOne = FracCos(DToFix(-.1));
  83.     sinNPtTwo = FracSin(DToFix(-.2));
  84.     cosNPtTwo = FracCos(DToFix(-.2));
  85. }
  86.  
  87.     
  88. typedef Fixed (*FProcPtr)() ;
  89.  
  90. Fixed    (*FixMAddrs)(), (*FixDAddrs)();
  91.  
  92. AddrsSet()
  93. {
  94.     FixMAddrs = (void *)GetTrapAddress(0x68);
  95.     FixDAddrs = (void *)GetTrapAddress(0x00);    /* I don't know what this should be */
  96. }
  97.  
  98. long
  99. _FixMul(a, b)
  100. long    a, b;
  101. {
  102. asm{
  103.     subq.l    #4,sp
  104.     move.l    a,-(sp)
  105.     move.l    b,-(sp)
  106.     move.l    FixMAddrs,a0
  107.     jsr        (a0)
  108.     move.l    (sp)+,d0
  109.     }
  110. }
  111.  
  112. long
  113. _FixDiv(a, b)
  114. long    a, b;
  115. {
  116. asm{
  117.     subq.l    #4,sp
  118.     move.l    a,-(sp)
  119.     move.l    b,-(sp)
  120.     move.l    FixDAddrs,a0
  121.     jsr        (a0)
  122.     move.l    (sp)+,d0
  123.     }
  124. }
  125.